package com.sc.socket.tcp;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.SocketException;

/**
 * @author shuc001
 * @Date 2019-02-03 20:26
 */
public class Server {

    public static void main(String[] args) throws IOException {
        ServerSocket ss = createSocket();
        initServerSocket(ss);
    }

    private static void initServerSocket(ServerSocket ss) throws SocketException {
        ss.setReuseAddress(true);
        ss.setReceiveBufferSize(64*1024*1024);
        ss.setSoTimeout(2000);
        ss.setPerformancePreferences(1,1,1);
    }

    private static ServerSocket createSocket() throws IOException {
        ServerSocket ss = new ServerSocket();
        //等待连接的队列容量为50
        ss.bind(new InetSocketAddress(InetAddress.getLocalHost(),20001),50);

        ss = new ServerSocket(20001,50);

        return ss;
    }
}
